package 最小栈;

import java.util.Stack;

class MinStack {
    Stack<Integer> s1 = new Stack<>();
    Stack<Integer> s2 = new Stack<>();
    public MinStack() {

    }
    
    public void push(int val) {
        s1.push(val);
        if(s2.empty()){
            s2.push(val);
        }else if (s2.peek()>=val){
            s2.push(val);
        }
    }
    
    public void pop() {
        int cur = s1.pop();
        if (s2.peek()==cur){
            s2.pop();
        }
    }
    
    public int top() {
        return s1.peek();
    }
    
    public int getMin() {
        return s2.peek();
    }
}